package org.geoserver.gwc.layer;

/** Author: LuoHaoLun Email : 506503279@qq.com Date : 2021/4/14 */
class AA {
    static {
        int ret = JnaLibrary.INSTANCE.CRYPTION_AES_CFB_INIT();
        System.out.println("初始化：" + ret);
    }

    private StringBuffer buffer = new StringBuffer();

    public byte[] decrypt(byte[] data) {
        buffer.setLength(0);
        for (int i = 0; i < data.length; i++) {
            String hs = Integer.toHexString(data[i] & 0xff);
            if (hs.length() < 2) buffer.append(0);
            buffer.append(hs);
        }
        char[] chars =
                JnaLibrary.INSTANCE
                        .AES_CFB_DECRYPT_STRING(buffer.toString(), buffer.length())
                        .toCharArray();

        buffer.setLength(0);
        byte[] bytes = new byte[chars.length / 2];
        int index = 0;
        for (char c : chars) {
            buffer.append(c);
            if (buffer.length() == 2) {
                bytes[index] = (byte) Integer.parseInt(buffer.toString(), 16);
                index++;
                buffer.setLength(0);
            }
        }
        return bytes;
    }
}
